package com.trhui.mallbook.client;

import com.trhui.mallbook.config.MallBookConfig;
import com.trhui.mallbook.domain.common.ApiRequest;
import com.trhui.mallbook.domain.common.BaseResponse;
import com.trhui.mallbook.domain.request.hf.HfBindAccountRequest;
import com.trhui.mallbook.domain.request.hf.HfUnbindAccountRequest;
import com.trhui.mallbook.domain.request.xib.XibBindAccountQueryRequest;
import com.trhui.mallbook.domain.request.xib.XibBindAccountRequest;
import com.trhui.mallbook.domain.request.xib.XibChangeAccountRequest;
import com.trhui.mallbook.domain.request.xib.XibOpenVerifyRequest;
import com.trhui.mallbook.domain.request.yb.YbBindAccountRequest;
import com.trhui.mallbook.domain.request.yb.YbUnbindAccountRequest;
import com.trhui.mallbook.domain.response.UnbindAccountResponse;
import com.trhui.mallbook.domain.response.hf.HfBindAccountResponse;
import com.trhui.mallbook.domain.response.xib.XibBindAccountQueryResponse;
import com.trhui.mallbook.domain.response.xib.XibBindAccountResponse;
import com.trhui.mallbook.domain.response.xib.XibOpenVerifyResponse;
import com.trhui.mallbook.domain.response.yb.YbBindAccountResponse;
import com.trhui.mallbook.enums.ChannelTypeEnum;
import com.trhui.mallbook.enums.ServerCodeEnum;


/**
 * @author huangh
 * @version 1.0
 * @description 子商户结算账户相关接口
 * @date 2023/08/17 0017 9:20
 */

public class UserAccountClient extends AbstractClient {

    /**
     * 汇付-子商户绑卡
     *
     * @param request
     * @return
     */
    public static BaseResponse<HfBindAccountResponse> hfBindAccount(HfBindAccountRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.BIND_ACCOUNT)
                .channelType(ChannelTypeEnum.HF)
                .build();
        return post(reqApiRequest, HfBindAccountResponse.class);
    }

    /**
     * 汇付子商户解绑结算账户接口
     * @param request
     * @return
     */
    public static BaseResponse<UnbindAccountResponse> hfUnbindAccount(HfUnbindAccountRequest request) {
        ApiRequest apiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.UNBIND_ACCOUNT)
                .channelType(ChannelTypeEnum.HF)
                .build();
        return post(apiRequest, UnbindAccountResponse.class);
    }

    /**
     * 易宝-子商户绑卡
     *
     * @param request
     * @return
     */
    public static BaseResponse<YbBindAccountResponse> ybBindAccount(YbBindAccountRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.BIND_ACCOUNT)
                .channelType(ChannelTypeEnum.YB)
                .build();
        return post(reqApiRequest, YbBindAccountResponse.class);
    }



    /**
     * 易宝子商户解绑结算账户接口
     * @param request
     * @return
     */
    public static BaseResponse<UnbindAccountResponse> ybUnbindAccount(YbUnbindAccountRequest request) {
        ApiRequest apiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.UNBIND_ACCOUNT)
                .channelType(ChannelTypeEnum.YB)
                .build();
        return post(apiRequest, UnbindAccountResponse.class);
    }

    /**
     * 厦门国际银行-子商户绑卡
     *
     * @param request
     * @return
     */
    public static BaseResponse<XibBindAccountResponse> xibBindAccount(XibBindAccountRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.BIND_ACCOUNT)
                .channelType(ChannelTypeEnum.XIB)
                .build();
        return post(reqApiRequest, XibBindAccountResponse.class);
    }

    /**
     * 厦门国际银行-子商户更换结算账户接口
     *
     * @param request
     * @return
     */
    public static ApiRequest xibChangeAccount(XibChangeAccountRequest request) {
        MallBookConfig config = MallBookConfig.getConfig(request.getMerchantNo());
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.CHANGE_ACCOUNT)
                .channelType(ChannelTypeEnum.XIB)
                .date(String.valueOf(System.currentTimeMillis()))
                .version(config.getVersion())
                .build(config.getMerchantPrivateKey());
        return reqApiRequest;
    }

    /**
     * 厦门国际银行-开户绑卡提交验证
     *
     * @param request
     * @return
     */
    public static BaseResponse<XibOpenVerifyResponse> xibVerifyMessage(XibOpenVerifyRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.VERIFY_MESSAGE)
                .channelType(ChannelTypeEnum.XIB)
                .build();
        return post(reqApiRequest, XibOpenVerifyResponse.class);
    }


    /**
     * 厦门国际银行-子商户绑卡查询
     * @param request
     * @return
     */
    public static BaseResponse<XibBindAccountQueryResponse> xibBindAccountQuery(XibBindAccountQueryRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.QUERY_BIND_CARD)
                .channelType(ChannelTypeEnum.XIB)
                .build();
        return post(reqApiRequest, XibBindAccountQueryResponse.class);
    }


}
